// 默认登录接口
export default {

	/* 返回对象实例 */
	make(vm) {
		return (this.vm = vm), this;
	},

	/* 初始化页面 */
	init() {},

	/* 获取本地用户 */
	local() {
		let that = this;
		return new Promise((resolve, reject) => {
			let user = that.vm.$u.cache.get('UserInfo', false);
			user ? resolve(user) : reject();
		});
	},

	/* 刷新本地用户 */
	reload() {
		let that = this;
		return new Promise((resolve, reject) => {
			that.local().then(ret => {
				that.vm.$u.get('data/api.auth.center/get').then(ret => {
					ret.code ? (that.update(ret.data), resolve(ret.data)) : reject(ret.info)
				});
			}, reject);
		});
	},

	/* 退出本地登录 */
	logout() {
		return new Promise((resolve, reject) => {
			this.vm.$u.cache.del('UserInfo');
			this.vm.$u.cache.del('UserToken');
			resolve();
		});
	},

	/* 更新用户数据 */
	update(UserInfo) {
		this.vm.$u.cache.set('UserInfo', UserInfo || {});
		this.vm.$u.cache.set('UserToken', UserInfo.token.token || '');
		return UserInfo;
	},
}
